package com.restcloud.run.MRS;

import com.restcloud.pojo.MedicalRecordSummary.*;
import com.restcloud.pojo.Public.*;
import com.restcloud.utils.XmlUtil;

import java.util.ArrayList;
import java.util.List;

public class Query {

    /**
     * 病历概要
     * @param args
     */
    public static void main(String[] args) {
        ClinicalDocument clinical = new ClinicalDocument();

        clinical.setTitle("病历概要");
        /**
         * 个人档案
         */
        MRSReceiver recordTarget = new MRSReceiver("RCT","OP");
        MRSDevice patientRole = new MRSDevice("PAT");

        patientRole.setId(new Id("2.16.156.10011.1.2","111111111111111"));

        Addr addr = new Addr("H");
        addr.setHouseNumber("");
        addr.setStreetName("");
        addr.setTownship("");
        addr.setCounty("");
        addr.setCity("");
        addr.setState("");
        addr.setPostalCode("");
        patientRole.setAddr(addr);

        patientRole.setTelecom(new Value("12345678"));

        MRSDevice patient = new MRSDevice("PSN","INSTANCE");
        patient.setId(new Id("2.16.156.10011.1.3","123123123"));
        patient.setName("北侧于");
        patient.setAdministrativeGenderCode(new Code("2","女性","2.16.156.10011.2.3.3.4","生理性别代码表(GB/T 2261.1)"));
        patient.setBirthTime(new Value("20000101"));
        patient.setMaritalStatusCode(new Code("20","已婚","2.16.156.10011.2.3.3.5","婚姻状况代码表(GB/T 2261.2)"));
        patient.setEthnicGroupCode(new Code("01","汉族","2.16.156.10011.2.3.3.3","民族类别代码表(GB 3304)"));
        patient.setEmployerOrganization(new Addr("-",new Value("-")));
        Addr occupation = new Addr();
        occupation.setOccupationCode(new Code("24","工人","2.16.156.10011.2.3.3.13","从业状况(个人身体)代码表(GB/T 2261.4)"));
        patient.setOccupation(occupation);

        patientRole.setPatient(patient);
        recordTarget.setPatientRole(patientRole);
        clinical.setRecordTarget(recordTarget);
        /**
         * 创建者
         */
        MRSReceiver mrsReceiver = new MRSReceiver("AUT", "OP");
        mrsReceiver.setTime(new Value("201401110828"));
        MRSDevice assignedAuthor = new MRSDevice("ASSIGNED");
        assignedAuthor.setId(new Id("1231231","1231231231"));
        List<String> name = new ArrayList<>();
        name.add("李飞飞");
        assignedAuthor.setAssignedPerson(name);
        MRSDevice representedOrganization = new MRSDevice();
        representedOrganization.setId(new Id("2.16.156.10011.1.5","13423234"));
        representedOrganization.setName("山东省立医院");
        assignedAuthor.setRepresentedOrganization(representedOrganization);
        mrsReceiver.setAssignedAuthor(assignedAuthor);
        clinical.setAuthor(mrsReceiver);
        /**
         * 保管机构
         */
        MRSReceiver custodian = new MRSReceiver("CST", "");
        MRSDevice assignedCustodian = new MRSDevice("ASSIGNED");
        MRSDevice representedCustodianOrganization = new MRSDevice();
        representedCustodianOrganization.setId(new Id("2.16.156.10011.1.5","13423234"));
        representedCustodianOrganization.setName("山东省立医院");
        assignedCustodian.setRepresentedCustodianOrganization(representedCustodianOrganization);
        custodian.setAssignedCustodian(assignedCustodian);
        clinical.setCustodian(custodian);

        MRSReceiver participant = new MRSReceiver("NOT", "");
        MRSDevice associatedEntity = new MRSDevice("ECON");
        associatedEntity.setCode(new Code());
        Addr addr1 = new Addr();
        addr1.setHouseNumber("");
        addr1.setStreetName("");
        addr1.setTownship("");
        addr1.setCounty("");
        addr1.setCity("");
        addr1.setState("");
        addr1.setPostalCode("");
        associatedEntity.setAddr(addr1);
        Value telecom = new Value();
        telecom.setUse("H");
        telecom.setValue("15806699256");
        associatedEntity.setTelecom(telecom);
        MRSDevice associatedPerson = new MRSDevice("PSN","INSTANCE");
        associatedPerson.setName("谢培玲");
        associatedEntity.setAssociatedPerson(associatedPerson);
        participant.setAssociatedEntity(associatedEntity);
        clinical.setParticipant(participant);

        MRSReceiver relatedDocument = new MRSReceiver("RPLC","");
        MRSDevice parentDocument = new MRSDevice();
        parentDocument.setId(new Id());
        parentDocument.setName("");
        parentDocument.setVersionNumber("");
        relatedDocument.setParentDocument(parentDocument);
        clinical.setParticipant(relatedDocument);

        MRSReceiver component = new MRSReceiver();
        MRSReceiver body = new MRSReceiver();
        List<MRSReceiver> structuredBody = new ArrayList<>();
        /**
         * 实验室检验章节
         */
        MRSReceiver v1 = new MRSReceiver();
        MRSSession s11 = new MRSSession();
        s11.setCode(new Code("30954-2","STUDIES SUMMARY","2.16.840.1.113883.6.1","LOINC"));
        s11.setText(new Code());
        List<MRSReceiver> entry11 = new ArrayList<>();
        MRSReceiver r11 = new MRSReceiver("COMP","");
        r11.setStatusCode(new Code());
        /**
         * 血型
         */
        List<MRSReceiver> com1 = new ArrayList<>();
        MRSReceiver blood1 = new MRSReceiver("COMP","true");
        MRSDevice obs1 = new MRSDevice("OBS");
        obs1.setMoodCode("EVN");
        obs1.setCode(new Code("DE04.50.001.00","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        obs1.setValue(new Code("CD","5","DE04.50.001.00","ABO血型代码表","卫生信息数据元目录"));
        blood1.setObservation(obs1);
        com1.add(blood1);
        MRSReceiver blood2 = new MRSReceiver("COMP","true");
        MRSDevice obs2 = new MRSDevice();
        obs2.setMoodCode("EVN");
        obs2.setCode(new Code("DE04.50.001.00","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        obs2.setValue(new Code("CD","5","DE04.50.001.00","Rh(D)血型代码表","卫生信息数据元目录"));
        blood2.setObservation(obs2);
        com1.add(blood2);
        r11.setComponent(com1);
        entry11.add(r11);
        s11.setEntry(entry11);
        v1.setSection(s11);
        structuredBody.add(v1);
        /**
         * 既往史章节
         */
        MRSReceiver v2 = new MRSReceiver();
        MRSSession s21 = new MRSSession();
        s21.setCode(new Code("30954-2","STUDIES SUMMARY","2.16.840.1.113883.6.1","LOINC"));
        s21.setText(new Code());
        List<MRSReceiver> entry21 = new ArrayList<>();
        MRSReceiver r21 = new MRSReceiver();

        MRSDevice observation1 = new MRSDevice("OBS");
        observation1.setMoodCode("EVN");
        observation1.setCode(new Code("DE02.10.026.00","疾病史（含外伤）","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code1 = new Text();
        code1.setType("ST");
        code1.setText("第一次入院情况（具体入出院时间不详）:患者于2010年因“子宫肌瘤”入院，入院后完善相关检查，行子宫肌瘤切除术，术后恢复好，出院。第二次入院情况（2013-08-27---2013-09-14）:患者因“接触性出血2年，发现子宫内膜癌10余天”入院。入院完善");
        observation1.setValueText(code1);
        r21.setObservation(observation1);

        entry21.add(r21);
        MRSReceiver r22 = new MRSReceiver();

        MRSDevice observation2 = new MRSDevice("OBS");
        observation2.setMoodCode("EVN");
        observation2.setCode(new Code("DE02.10.026.00","疾病史（含外伤）","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code2 = new Text();
        code2.setType("ST");
        code2.setText("否认结核等传染病");
        observation2.setValueText(code2);
        r22.setObservation(observation2);

        entry21.add(r22);
        MRSReceiver r23 = new MRSReceiver();

        MRSDevice observation3 = new MRSDevice("OBS");
        observation3.setMoodCode("EVN");
        observation3.setCode(new Code("DE02.10.026.00","疾病史（含外伤）","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code3 = new Text();
        code3.setType("ST");
        code3.setText("可见");
        observation3.setValueText(code3);
        r23.setObservation(observation3);

        entry21.add(r23);
        MRSReceiver r24 = new MRSReceiver();

        MRSDevice observation4 = new MRSDevice("OBS");
        observation4.setMoodCode("EVN");
        observation4.setCode(new Code("DE02.10.026.00","疾病史（含外伤）","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code4 = new Text();
        code4.setType("ST");
        code4.setText("既往月经规律，，色红，量中等，无血块，无痛经，白带正常，无异味。27岁初婚，42岁再婚。患者目前实际年龄48岁。G0P0。丈夫体健。");
        observation4.setValueText(code4);
        r24.setObservation(observation4);

        entry21.add(r24);
        s21.setEntry(entry21);
        v2.setSection(s21);
        structuredBody.add(v2);
        /**
         * 输血章节
         */
        MRSReceiver v3 = new MRSReceiver();
        MRSSession s31 = new MRSSession();
        s31.setCode(new Code("30954-2","STUDIES SUMMARY","2.16.840.1.113883.6.1","LOINC"));
        s31.setText(new Code());
        List<MRSReceiver> entry31 = new ArrayList<>();
        MRSReceiver r31 = new MRSReceiver();

        MRSDevice observation21 = new MRSDevice("OBS");
        observation21.setMoodCode("EVN");
        observation21.setCode(new Code("DE02.10.026.00","疾病史（含外伤）","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code21 = new Text();
        code21.setType("ST");
        code21.setText("未知");
        observation21.setValueText(code21);
        r31.setObservation(observation21);

        entry31.add(r31);
        s31.setEntry(entry31);
        v3.setSection(s31);
        structuredBody.add(v3);
        /**
         * 过敏史章节
         */
        MRSReceiver v4 = new MRSReceiver();
        MRSSession s41 = new MRSSession();
        s41.setCode(new Code("30954-2","STUDIES SUMMARY","2.16.840.1.113883.6.1","LOINC"));
        s41.setText(new Code());
        List<MRSReceiver> entry41 = new ArrayList<>();
        MRSReceiver r41 = new MRSReceiver();

        MRSDevice observation31 = new MRSDevice("OBS");
        observation31.setMoodCode("EVN");
        observation31.setCode(new Code("DE02.10.026.00","疾病史（含外伤）","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code31 = new Text();
        code31.setType("ST");
        code31.setText("未知");
        observation31.setValueText(code31);
        r41.setObservation(observation31);

        entry41.add(r41);
        s41.setEntry(entry41);
        v4.setSection(s41);
        structuredBody.add(v4);
        /**
         * 预防接种史章节
         */
        MRSReceiver v5 = new MRSReceiver();
        MRSSession s51 = new MRSSession();
        s51.setCode(new Code("30954-2","STUDIES SUMMARY","2.16.840.1.113883.6.1","LOINC"));
        s51.setText(new Code());
        List<MRSReceiver> entry51 = new ArrayList<>();
        MRSReceiver r51 = new MRSReceiver();

        MRSDevice observation41 = new MRSDevice("OBS");
        observation41.setMoodCode("EVN");
        observation41.setCode(new Code("DE02.10.026.00","预防接种史","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code41 = new Text();
        code41.setType("ST");
        code41.setText("未知");
        observation41.setValueText(code41);
        r51.setObservation(observation41);

        entry51.add(r51);
        s51.setEntry(entry51);
        v5.setSection(s51);
        structuredBody.add(v5);
        /**
         * 个人史章节
         */
        MRSReceiver v6 = new MRSReceiver();
        MRSSession s61 = new MRSSession();
        s61.setCode(new Code("30954-2","STUDIES SUMMARY","2.16.840.1.113883.6.1","LOINC"));
        s61.setText(new Code());
        List<MRSReceiver> entry61 = new ArrayList<>();
        MRSReceiver r61 = new MRSReceiver();

        MRSDevice observation51 = new MRSDevice("OBS");
        observation51.setMoodCode("EVN");
        observation51.setCode(new Code("DE02.10.026.00","个人史","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code51 = new Text();
        code51.setType("ST");
        code51.setText("出生于当地，无外地久居史，无烟酒等不良嗜好。");
        observation51.setValueText(code51);
        r61.setObservation(observation51);

        entry61.add(r61);
        s61.setEntry(entry61);
        v6.setSection(s61);
        structuredBody.add(v6);
        /**
         * 月经史章节
         */
        MRSReceiver v7 = new MRSReceiver();
        MRSSession s71 = new MRSSession();
        s71.setCode(new Code("30954-2","STUDIES SUMMARY","2.16.840.1.113883.6.1","LOINC"));
        s71.setText(new Code());
        List<MRSReceiver> entry71 = new ArrayList<>();
        MRSReceiver r71 = new MRSReceiver();

        MRSDevice observation61 = new MRSDevice("OBS");
        observation61.setMoodCode("EVN");
        observation61.setCode(new Code("DE02.10.026.00","月经史","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code61 = new Text();
        code61.setType("ST");
        code61.setText("既往月经规律，，色红，量中等，无血块，无痛经，白带正常，无异味。");
        observation61.setValueText(code61);
        r71.setObservation(observation61);

        entry71.add(r71);
        s71.setEntry(entry71);
        v7.setSection(s71);
        structuredBody.add(v7);
        /**
         * 家族史章节
         */
        MRSReceiver v8 = new MRSReceiver();
        MRSSession s81 = new MRSSession();
        s81.setCode(new Code("30954-2","STUDIES SUMMARY","2.16.840.1.113883.6.1","LOINC"));
        s81.setText(new Code());
        List<MRSReceiver> entry81 = new ArrayList<>();
        MRSReceiver r81 = new MRSReceiver();

        MRSDevice observation71 = new MRSDevice("OBS");
        observation71.setMoodCode("EVN");
        observation71.setCode(new Code("DE02.10.026.00","月经史","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code71 = new Text();
        code71.setType("ST");
        code71.setText("父母健在，否认家族性遗传病及传染病史。");
        observation71.setValueText(code71);
        r81.setObservation(observation71);

        entry81.add(r81);
        s81.setEntry(entry81);
        v8.setSection(s81);
        structuredBody.add(v8);
        /**
         * 卫生事件章节
         */
        MRSReceiver v9 = new MRSReceiver();
        MRSSession s91 = new MRSSession();
        s91.setCode(new Code("30954-2","STUDIES SUMMARY","2.16.840.1.113883.6.1","LOINC"));
        s91.setText(new Code());
        List<MRSReceiver> entry91 = new ArrayList<>();
        MRSReceiver r91 = new MRSReceiver();

        MRSDevice organizer1 = new MRSDevice("BATTERY");
        organizer1.setMoodCode("EVN");
        organizer1.setStatusCode(new Value());
        List<MRSReceiver> component1 = new ArrayList<>();
        MRSReceiver receiver1 = new MRSReceiver();

        MRSDevice observation81 = new MRSDevice("OBS");
        observation81.setMoodCode("EVN");
        observation81.setCode(new Code("DE02.10.026.00","入院日期时间","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code81 = new Text();
        code81.setType("ST");
        code81.setText("201401110828");
        observation81.setValueText(code81);
        receiver1.setObservation(observation81);

        component1.add(receiver1);
        MRSReceiver receiver2 = new MRSReceiver();

        MRSDevice observation82 = new MRSDevice("OBS");
        observation82.setMoodCode("EVN");
        observation82.setCode(new Code("DE02.10.026.00","出院日期时间","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        Text code82 = new Text();
        code82.setType("ST");
        code82.setText("201401150959");
        observation82.setValueText(code82);
        receiver2.setObservation(observation82);

        component1.add(receiver2);
        organizer1.setComponent(component1);

        r91.setOrganizer(organizer1);

        entry91.add(r91);

        MRSReceiver r92 = new MRSReceiver();

        MRSDevice organizer2 = new MRSDevice("OBS");
        organizer2.setMoodCode("EVN");
        Code qualifier1 = new Code("DE02.10.026.00", "西医诊断编码", "2.16.156.10011.2.2.1", "卫生信息数据元目录");
        List<Code> qualifier = new ArrayList<>();
        qualifier.add(new Code("西医诊断编码"));
        qualifier1.setQualifier(qualifier);
        organizer2.setCode(qualifier1);
        organizer2.setValue(new Code("CD","Z51.102","2.16.156.10011.2.3.3.11","ICD-10","手术后恶性肿瘤化学治疗"));

        List<MRSReceiver> entryRelationship1 = new ArrayList<>();
        MRSReceiver entryShip1 = new MRSReceiver();
        entryShip1.setTypeCode("COMP");
        MRSDevice observation92 = new MRSDevice("OBS");
        observation92.setMoodCode("EVN");
        observation92.setCode(new Code("DE02.10.026.00","病情转归代码","2.16.156.10011.2.2.1","卫生信息数据元目录"));
        observation92.setValue(new Code("CD","1","2.16.156.10011.2.3.3.11","病情转归代码表","治愈"));
        entryShip1.setObservation(observation92);
        entryRelationship1.add(entryShip1);
        organizer2.setEntryRelationship(entryRelationship1);

        r92.setObservation(organizer2);

        entry91.add(r92);
        s91.setEntry(entry91);
        v9.setSection(s91);
        structuredBody.add(v9);
        body.setComponent(structuredBody);
        component.setStructuredBody(body);
        clinical.setComponent(component);

        String s = XmlUtil.beanToXml(clinical, ClinicalDocument.class, "GBK");
        System.out.println(s);
    }
}
